home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / D-G / Floating Windows.cpt / Floating Windows / FloatTest.p < prev    next >
Encoding:
Text File  |  1991-11-13  |  5.1 KB  |  304 lines  |  [TEXT/PJMM]

  1. PROGRAM FloatTest;
  2.  
  3. USES
  4.     Floating;
  5.  
  6. CONST
  7.     TypeMask = $FF000000;
  8.     SuspendResumeEvt = $1000000;
  9.     SuspendResumeBit = 1;
  10.  
  11.     mApple = 128;
  12.     iAbout = 1;
  13.     mFile = 129;
  14.     iQuit = 1;
  15.  
  16. VAR
  17.     windowA, windowB, windowC: WindowPtr;
  18.     floatWindow1, floatWindow2, floatWindow3: WindowPtr;
  19.     running, WNEImplemented, inBackground: Boolean;
  20.  
  21.  
  22. PROCEDURE Initialize;
  23.     VAR
  24.         theMBar: Handle;
  25.  
  26.     BEGIN
  27.         MaxApplZone;    { ??? }
  28.         MoreMasters;
  29.         InitGraf(@thePort);
  30.         InitFonts;
  31.         InitWindows;
  32.         InitMenus;
  33.         InitDialogs(NIL);
  34.         InitCursor;
  35.  
  36.         theMBar := GetNewMBar(128);
  37.         SetMenuBar(theMBar);
  38.         DrawMenuBar;
  39.  
  40.         WNEImplemented := (NGetTrapAddress($60, ToolTrap) <> NGetTrapAddress($9F, ToolTrap));
  41.         inBackground := false;
  42.         running := true;
  43.         InitFloat;
  44.     END;
  45.  
  46. PROCEDURE MakeWindows;
  47.     BEGIN
  48.         floatWindow1 := NewFloatingWindow(131, NIL);
  49.         floatWindow2 := NewFloatingWindow(132, NIL);
  50.         floatWindow3 := NewFloatingWindow(133, NIL);
  51.  
  52.         windowA := GetNewWindow(128, NIL, NIL);
  53.         SelectTheWindow(windowA);
  54.  
  55.         windowB := GetNewWindow(129, NIL, NIL);
  56.         SelectTheWindow(windowB);
  57.  
  58.         windowC := GetNewWindow(130, NIL, NIL);
  59.         SelectTheWindow(windowC);
  60.  
  61.     END;
  62.  
  63.  
  64. PROCEDURE doAbout;
  65.     CONST
  66.         kAboutAlrtID = 128;
  67.  
  68.     VAR
  69.         itemHit: Integer;
  70.  
  71.     BEGIN
  72.         itemHit := Alert(kAboutAlrtID, NIL);
  73.     END;
  74.  
  75.  
  76. PROCEDURE DoMenu (mResult: LongInt);
  77.     VAR
  78.         theMenu, theItem: Integer;
  79.         mHandle: MenuHandle;
  80.  
  81.     BEGIN
  82.         mHandle := GetMHandle(theMenu);
  83.  
  84.         theMenu := HiWord(mResult);
  85.         theItem := LoWord(mResult);
  86.  
  87.         CASE theMenu OF
  88.             mApple: 
  89.                 CASE theItem OF
  90.                     iAbout: 
  91.                         doAbout;
  92.                 END;
  93.  
  94.             mFile: 
  95.                 CASE theItem OF
  96.                     iQuit: 
  97.                         running := FALSE;
  98.  
  99.                     OTHERWISE
  100.                         ;
  101.                 END;
  102.  
  103.             OTHERWISE
  104.                 ;
  105.         END;
  106.  
  107.         HiliteMenu(0);
  108.     END;
  109.  
  110.  
  111. PROCEDURE GrowTheWindow (whichWindow: WindowPtr; where: Point);
  112.     VAR
  113.         newBounds: LongInt;
  114.         growRect: Rect;
  115.         savePort: GrafPtr;
  116.  
  117.     BEGIN
  118.         GetPort(savePort);
  119.         SetPort(whichWindow);
  120.         SetRect(growRect, 200, 150, 500, 300);
  121.         newBounds := GrowWindow(whichWindow, where, growRect);
  122.         IF newBounds <> 0 THEN
  123.         BEGIN
  124.             EraseRect(whichWindow^.portRect);
  125.             SizeWindow(whichWindow, LoWord(newBounds), HiWord(newBounds), true);
  126.             InvalRect(whichWindow^.portRect);
  127.         END;
  128.         SetPort(savePort);
  129.     END;
  130.  
  131.  
  132. PROCEDURE ZoomTheWindow (whichWindow: WindowPtr; where: Point; inOrOut: Integer);
  133.     VAR
  134.         portRect: Rect;
  135.  
  136.     BEGIN
  137.         IF TrackBox(whichWindow, where, inOrOut) THEN
  138.         BEGIN
  139.             portRect := whichWindow^.portRect;
  140.             EraseRect(portRect);
  141.             ZoomWindow(whichWindow, inOrOut, false);
  142.             portRect := whichWindow^.portRect;
  143.             InvalRect(portRect);
  144.         END;
  145.     END;
  146.  
  147.  
  148. PROCEDURE DoActivate (whichWindow: WindowPtr);
  149.     BEGIN
  150.         SetPort(whichWindow);
  151.         DrawGrowIcon(whichWindow);
  152.     END;
  153.  
  154.  
  155. PROCEDURE DoDeactivate (whichWindow: WindowPtr);
  156.     BEGIN
  157.         SetPort(whichWindow);
  158.         DrawGrowIcon(whichWindow);
  159.     END;
  160.  
  161.  
  162. PROCEDURE DoUpdate (whichWindow: WindowPtr);
  163.     VAR
  164.         savePort: GrafPtr;
  165.  
  166.     BEGIN
  167.         GetPort(savePort);
  168.         SetPort(whichWindow);
  169.         BeginUpdate(whichWindow);
  170.  
  171.         { do your drawing here... }
  172.  
  173.         DrawGrowIcon(whichWindow);
  174.         EndUpdate(whichWindow);
  175.         SetPort(savePort);
  176.     END;
  177.  
  178.  
  179. PROCEDURE DoResume (theEvent: EventRecord);
  180.     BEGIN
  181.         inBackground := FALSE;
  182.         ShowFloats;
  183.     END;
  184.  
  185.  
  186. PROCEDURE DoSuspend (theEvent: EventRecord);
  187.     BEGIN
  188.         inBackground := TRUE;
  189.         HideFloats;
  190.     END;
  191.  
  192.  
  193. PROCEDURE DoMouseDown (theEvent: EventRecord);
  194.     VAR
  195.         whichWindow: WindowPtr;
  196.         thePart: Integer;
  197.  
  198.     BEGIN
  199.         thePart := FindWindow(theEvent.where, whichWindow);
  200.         CASE thePart OF
  201.             inDesk: 
  202.                 ;
  203.             inMenuBar: 
  204.                 DoMenu(MenuSelect(theEvent.where));
  205.             inSysWindow: 
  206.                 SystemClick(theEvent, whichWindow);
  207.             inContent: 
  208.                 SelectTheWindow(whichWindow);
  209.             inDrag: 
  210.                 DragTheWindow(whichWindow, theEvent);
  211.             inGrow: 
  212.                 GrowTheWindow(whichWindow, theEvent.where);
  213.  
  214.             inGoAway: 
  215.             BEGIN
  216.                 IF TrackGoAway(whichWindow, theEvent.where) THEN
  217.                     CloseTheWindow(whichWindow);
  218.                 IF FrontWindow = NIL THEN
  219.                     running := FALSE;
  220.             END;
  221.  
  222.             inZoomIn, inZoomOut: 
  223.                 ZoomTheWindow(whichWindow, theEvent.where, thePart);
  224.         END;
  225.     END;
  226.  
  227.  
  228. PROCEDURE DoEvent (theEvent: EventRecord);
  229.     VAR
  230.         ch: Char;
  231.         whichWindow: WindowPtr;
  232.  
  233.     BEGIN
  234.         whichWindow := WindowPtr(theEvent.message);
  235.  
  236.         CASE theEvent.what OF
  237.             nullEvent: 
  238.                 ;
  239.             mouseDown: 
  240.                 DoMouseDown(theEvent);
  241.  
  242.             keyDown: 
  243.             BEGIN
  244.                 ch := CHR(BAnd(theEvent.message, charCodeMask));
  245.                 IF BAnd(theEvent.modifiers, cmdKey) = cmdKey THEN
  246.                     DoMenu(MenuKey(ch));
  247.             END;
  248.  
  249.             activateEvt: 
  250.                 IF BAND(theEvent.modifiers, activeFlag) = activeFlag THEN
  251.                     DoActivate(whichWindow)
  252.                 ELSE
  253.                     DoDeactivate(whichWindow);
  254.  
  255.             updateEvt: 
  256.                 DoUpdate(whichWindow);
  257.  
  258.             app4Evt: 
  259.             BEGIN
  260.                 CASE BAND(theEvent.message, TypeMask) OF
  261.                     SuspendResumeEvt: 
  262.                         IF BAND(theEvent.message, SuspendResumeBit) = suspendResumeBit THEN
  263.                             DoResume(theEvent)
  264.                         ELSE
  265.                             DoSuspend(theEvent);
  266.                 END;
  267.             END;
  268.  
  269.             OTHERWISE
  270.                 ;
  271.         END;
  272.  
  273.     END;
  274.  
  275.  
  276. PROCEDURE EventLoop;
  277.     VAR
  278.         theEvent: EventRecord;
  279.  
  280.     BEGIN
  281.         REPEAT
  282.             IF WNEImplemented THEN
  283.             BEGIN
  284.                 IF WaitNextEvent(everyEvent, theEvent, 0, NIL) THEN
  285.                     DoEvent(theEvent);
  286.             END
  287.             ELSE
  288.             BEGIN
  289.                 SystemTask;
  290.                 IF GetNextEvent(everyEvent, theEvent) THEN
  291.                     DoEvent(theEvent);
  292.             END;
  293.         UNTIL NOT running;
  294.     END;
  295.  
  296.  
  297. BEGIN
  298.     Initialize;
  299.     MakeWindows;
  300.  
  301.     EventLoop;
  302.  
  303.     ExitToShell;
  304. END.